<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="javax.servlet.http.Cookie" %>
<%
    // 减少当前在线用户数
    Integer currentUsers = (Integer)application.getAttribute("currentUsers");
    if(currentUsers != null && currentUsers > 0) {
        application.setAttribute("currentUsers", currentUsers - 1);
    }

    // 使session失效
    session.invalidate();

    // 删除记住我相关的cookie
    Cookie[] cookies = request.getCookies();
    if(cookies != null) {
        for(Cookie cookie : cookies) {
            if("rememberMeUser".equals(cookie.getName()) || "rememberMe".equals(cookie.getName())) {
                cookie.setMaxAge(0);
                response.addCookie(cookie);
            }
        }
    }

    response.sendRedirect("login.jsp");
%>